﻿Imports Microsoft.VisualBasic
Imports System.Configuration

Public Class Functions
    Inherits System.Web.UI.Page
    Public RecSet As ADODB.Recordset
    Public RecSet2 As ADODB.Recordset
    Public countryID As Object
    Public Conn As New ADODB.Connection
    Public flsPartnerWebID As Object ' System.Object
    Public flsPartnerWebType As Object ' System.Object
    Public userID As Integer
    Public strJS As Object
    Public strSelectSubHeadline As Object
    Public strSelectSubJS As Object
    Public coCompany As Object ' System.Object
    Public coStreet As Object ' System.Object
    Public coZipcode As Object ' System.Object
    Public coCity As Object ' System.Object
    Public coTelephone As Object ' System.Object
    Public coFax As Object ' System.Object
    Public coEmail As Object ' System.Object
    Public coHomepage As Object ' System.Object
    Public coCountry As Object ' System.Object
    Public coCin As Object ' System.Object
    Public globalPartnerID As Object ' System.Object
    Public intClientID As Object
    Public ClientTypeIDContract As Object

    'Hämta ut rätt clientnamn beroende på företag och privatperson
    Function GetClientName(clientype As Integer, clientID As Integer) As String
        Dim clientname As String
        clientname = String.Empty

        Dim firstname As String
        Dim lastname As String
        ' dbOpen()
        Dim sql As String
        sql = String.Format("select clientid,client,client_lastname from tblclient where clientid={0}", clientID)
        RecSet2 = Conn.Execute(sql)


        firstname = RecSet2.Fields("client").Value
        If (RecSet2.Fields("client_lastname").Value <> Nothing) Then
            lastname = Convert.ToString(RecSet2.Fields("client_lastname").Value)
        Else
            lastname = String.Empty
        End If

        '   lastname = Convert.ToString(RecSet2.Fields("client_lastname").Value)
        'När vi har clienttypen kolla vilken 1 privatperson
        '2 är företag måste också se när vi bärjade använda efternamn för clienttypen och köra specialfall där.
        'clientid >1697 då har vi för och efternamn

        'Lägg det i en basfunktion för alla kontrakt.
        'skicka in vehicleid, clienttype, client

        'privatperson
        If clientype = 1 Then
            'större än 1697 då har vi både för och efternamn
            If (clientID > 1697) Then
                clientname = String.Format("{0} {1}", firstname, lastname)
            Else
                clientname = firstname
            End If
            'företag
        ElseIf clientype = 2 Then
            clientname = firstname
        End If
        '   dbClose()

        Return clientname
    End Function
    'Kolla om fordonet använder sig av nya prissystemet
    Public Function IsNewPricelistContract(vehicleID As Integer) As Boolean
        Dim isNewPrice As Boolean = False
        '  dbOpen()

        Dim sqlstr As String = "SELECT        b.brandid,m.modelid,v.clientID, v.regnr, v.vinNumber, v.cylinderVolume,v.isDieselcar, v.date, b.brand, m.model, u.username, tblPriceList.ServiceIntervall, tblPriceList.isDieselcar" +
                 "   FROM            tblVehicle AS v INNER JOIN " +
                 "            tblBrand AS b ON b.brandID = v.brandID INNER JOIN " +
                 "            tblModel AS m ON m.modelID = v.modelID INNER JOIN " +
                 "            tblUser AS u ON u.userID = v.userID INNER JOIN " +
                 "            tblPriceList ON v.priceListID = tblPriceList.priceListID " +
        String.Format(" Where v.vehicleID ={0}", vehicleID)

        '  RecSet = Conn.Execute("Select v.clientID, v.regnr, v.vinNumber, v.cylinderVolume, v.date, b.brand, m.model, u.username From (((tblVehicle v INNER JOIN tblBrand b ON b.brandID = v.brandID) INNER JOIN tblModel m ON m.modelID = v.modelID) INNER JOIN tblUser u ON u.userID = v.userID) Where v.vehicleID = " & vehicleID & "")
        RecSet = Conn.Execute(sqlstr)

        If RecSet.EOF Then
            Return False
        Else

            Dim brandID As Object = RecSet.Fields("brandid").Value
            Dim modelID As Object = RecSet.Fields("modelid").Value

            If (brandID = 118 And modelID = 1462) Then
                isNewPrice = True
            End If
        End If
        Return isNewPrice
    End Function

    'Fyll kontraktinfo, det som syns på kontraktet.
    Public Sub FillPrintInfo(ByRef a As Object, ByRef b As Object, ByRef c As Object, ByRef d As Object, ByRef e As Object, ByRef f As Object, ByRef g As Object, ByRef h As Object, ByRef i As Object, ByRef j As Object,
                      ByRef k As Object, ByRef l As Object, ByRef m As Object, ByRef n As Object, ByRef o As Object, ByRef p As Object, ByRef q As Object, ByRef r As Object, ByRef s As Object, ByRef t As Object,
                      ByRef u As Object, ByRef v As Object, ByRef x As Object, ByRef y As Object, ByRef z As Object, ByRef a1 As Object, ByRef b1 As Object, ByRef c1 As Object, ByRef d1 As Object, ByRef e1 As Object,
                      vehicleID As Integer)

        dbOpen()
        Dim sql As String
        Dim sqlOld As String

        sql = "                   SELECT        v.partnerID, v.productID, c.clientType, v.contractNumber, v.vinNumber, v.regnr, v.paymentMethod, v.firstRegistrationDate, v.leaseStartDate, v.leaseStartKms, " +
     "                    d.dealer, d.city AS dealerCity, c.client,c.clientid, c.cin, c.numberofIDDateAndPlace, c.customerIdentification, c.areacode, c.telephone, c.street, c.zipcode, c.city AS clientCity, " +
      "                   VehicleInfo.Marke AS brand, VehicleInfo.Modell + ' ' + vehicleinfo.typ AS model, pl.priceListDuration, pl.priceListDistance, pl.price, co.countryCurrency, co.decimals, p.invoiceFee, " +
       "                  de.dealerEmployee," +
        "                     (SELECT        TOP (1) salesTax " +
         "                      FROM            tblSalesTax AS st " +
          "                     WHERE        (countryID = c.countryID) AND (date <= v.date) " +
           "                    ORDER BY date DESC) AS salesTax " +
"FROM            tblVehicle AS v INNER JOIN " +
 "                        tblDealer AS d ON d.dealerID = v.dealerID INNER JOIN " +
  "                       tblClient AS c ON c.clientID = v.clientID INNER JOIN " +
   "                      tblBrand AS b ON b.brandID = v.brandID INNER JOIN " +
   "                      tblModel AS m ON m.modelID = v.modelID INNER JOIN " +
    "                     tblPriceList AS pl ON pl.priceListID = v.priceListID INNER JOIN " +
     "                    tblCountry AS co ON co.countryID = v.countryID INNER JOIN " +
      "                   tblPartner AS p ON p.partnerID = v.partnerID INNER JOIN " +
       "                  VehicleInfo ON pl.Typkod = VehicleInfo.Typkod LEFT OUTER JOIN " +
        "                 tblDealerEmployee AS de ON de.dealerEmployeeID = v.dealerEmployeeID " +
        String.Format("Where v.vehicleID = {0}", vehicleID)

        sqlOld = String.Format("Select v.partnerID, v.productID, v.contractNumber, v.vinNumber, v.regnr, v.paymentMethod, v.firstRegistrationDate, v.leaseStartDate, v.leaseStartKms, d.Dealer, d.city As dealerCity,c.clientid, c.client,c.clientType, c.cin,c.numberofIDDateAndPlace, c.customerIdentification, c.areacode, c.telephone, c.street, c.zipcode, c.city As clientCity, b.brand, m.model, pl.priceListDuration, pl.priceListDistance, pl.price, co.countryCurrency, co.decimals, p.invoiceFee, de.dealerEmployee, (Select TOP 1 salesTax From tblSalesTax st Where st.countryID = c.countryID And st.date <= v.date Order By st.date desc) As salesTax From ((((((((tblVehicle v INNER JOIN tblDealer d ON d.dealerID = v.dealerID) INNER JOIN tblClient c ON c.clientID = v.clientID) INNER JOIN tblBrand b ON b.brandID = v.brandID) INNER JOIn tblModel m ON m.modelID = v.modelID) INNER JOIN tblPriceList pl ON pl.priceListID = v.priceListID) INNER JOIN tblCountry co ON co.countryID = v.countryID) INNER JOIN tblPartner p ON p.partnerID = v.partnerID) LEFT JOIN tblDealerEmployee de ON de.dealerEmployeeID = v.dealerEmployeeID) Where v.vehicleID = {0}", vehicleID)

        If IsNewPricelistContract(vehicleID) Then
            RecSet = Conn.Execute(sql)
        Else
            RecSet = Conn.Execute(sqlOld)
        End If

        ClientTypeIDContract = RecSet.Fields("clientType").Value

        a = RecSet.Fields("partnerID").Value
        b = RecSet.Fields("productID").Value
        c = RecSet.Fields("contractNumber").Value
        d = RecSet.Fields("vinNumber").Value
        e = RecSet.Fields("regnr").Value
        f = RecSet.Fields("paymentMethod").Value
        g = RecSet.Fields("firstRegistrationDate").Value
        h = RecSet.Fields("leaseStartDate").Value
        i = RecSet.Fields("leaseStartKms").Value
        j = RecSet.Fields("dealer").Value
        k = RecSet.Fields("dealerCity").Value

        'Check the clienttype company or private
        '   client = RecSet.Fields("client").Value
        l = RecSet.Fields("cin").Value
        m = RecSet.Fields("areacode").Value
        n = RecSet.Fields("telephone").Value
        o = RecSet.Fields("street").Value
        p = RecSet.Fields("zipcode").Value
        q = RecSet.Fields("clientCity").Value
        r = RecSet.Fields("brand").Value
        s = RecSet.Fields("model").Value
        t = RecSet.Fields("priceListDuration").Value
        u = RecSet.Fields("priceListDistance").Value
        v = RecSet.Fields("price").Value
        x = RecSet.Fields("countryCurrency").Value
        y = RecSet.Fields("decimals").Value
        z = RecSet.Fields("invoiceFee").Value
        a1 = RecSet.Fields("dealerEmployee").Value
        b1 = RecSet.Fields("salesTax").Value



        If IsDBNull(RecSet.Fields("numberofIDDateAndPlace").Value) Then
            c1 = String.Empty
        Else
            c1 = Convert.ToString(RecSet.Fields("numberofIDDateAndPlace").Value)
        End If

        If IsDBNull(RecSet.Fields("customerIdentification").Value) Then
            d1 = 0
        Else
            d1 = Convert.ToString(RecSet.Fields("customerIdentification").Value)
        End If



        e1 = GetClientName(ClientTypeIDContract, Convert.ToInt32(RecSet.Fields("clientID").Value))

        RecSet.Close()
        RecSet2.Close()

        RecSet = Nothing
        RecSet2 = Nothing

        dbClose()

    End Sub

    Protected Overridable Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        Response.Buffer = True
        Session.LCID = 1053
        flsPartnerWebID = Session("flsPartnerWebID")
        flsPartnerWebType = Session("flsPartnerWebType")
        userID = 19
        If Len(flsPartnerWebID) = 0 Then
            Response.Redirect("logOut.aspx?error=6")
        End If
        Session.Add("flsPartnerWebID", flsPartnerWebID)
        Session.Add("flsPartnerWebType", flsPartnerWebType)
        Session.Timeout = 120
    End Sub

    Sub dbOpen()
        Conn = New ADODB.ConnectionClass()
        Conn.Open((ConfigurationManager.ConnectionStrings("DatabaseConnection").ConnectionString))
    End Sub

    Sub dbClose()
        Conn.Close()
        Conn = Nothing
    End Sub

    Sub Over()
        Response.Write("<html>")
        Response.Write("<head>")
        Response.Write("<title>FLS Partner Web</title>")
        'Response.Write "<script language='JavaScript' src='fieldFocus.js'></script>"
        Response.Write("<link rel='stylesheet' href='style.css'>")
        Response.Write("<script type=""text/javascript"">" & vbCr)
        Response.Write("	  function OnLoadFunctions(){" & vbCr)
        Response.Write("	    //hide loading status..." & vbCr)
        Response.Write("	    document.getElementById(""loading"").style.display='none';" & vbCr)
        Response.Write("	    //show content" & vbCr)
        Response.Write("	    document.getElementById(""content"").style.display='block';" & vbCr)
        Response.Write("	    if (document.forms.length > 0) {" & vbCr)
        Response.Write("	      var field = document.forms[0];" & vbCr)
        Response.Write("	      for (i = 0; i < field.length; i++) {" & vbCr)
        Response.Write("		if ((field.elements[i].type == ""text"") || (field.elements[i].type == ""textarea"") || (field.elements[i].type.toString().charAt(0) == ""s"")) {" & vbCr)
        Response.Write("		  document.forms[0].elements[i].focus();" & vbCr)
        Response.Write("		  break;" & vbCr)
        Response.Write("		}" & vbCr)
        Response.Write("	      }" & vbCr)
        Response.Write("	    }" & vbCr)
        Response.Write("	  }" & vbCr)
        Response.Write("	</script>" & vbCr)
        Response.Write("</head>")
        Response.Write("<body OnLoad=""OnLoadFunctions()"">")
        Response.Write("<script type=""text/javascript"">" & vbCr)
        Response.Write("	  document.write('<div id=""loading""><center><img src=""gui/progressBar.gif""><br><br>System loading. Please wait...</center></div>');" & vbCr)
        Response.Write("	</script>" & vbCr)
        Response.Write("	<div id=""content"">" & vbCr)
        Response.Write("<script type=""text/javascript"">" & vbCr)
        Response.Write("	    //hide content" & vbCr)
        Response.Write("	    document.getElementById(""content"").style.display='none';" & vbCr)
        Response.Write("	  </script>" & vbCr)
        Response.Write("<script language='JavaScript' src='menu.js'></script>")
        Response.Write("<script language='JavaScript' src='menu_items.js'></script>")
        Response.Write("<script language='JavaScript' src='menu_tpl.js'></script>")
        Response.Write("<script language='JavaScript'>")
        Response.Write("new menu (MENU_ITEMS, MENU_POS);")
        Response.Write("</script>")
        If flsPartnerWebType = "p" Then
            globalPartnerID = flsPartnerWebID
        ElseIf flsPartnerWebType = "d" Then
            dbOpen()
            RecSet = Conn.Execute("Select partnerID As globalPartnerID From tblDealer Where dealerID = " & flsPartnerWebID & "")
            If Not RecSet.EOF Then
                globalPartnerID = RecSet.Fields("globalPartnerID").Value
            End If
            RecSet.Close()
            RecSet = Nothing
            dbClose()
        ElseIf flsPartnerWebType = "de" Then
            dbOpen()
            RecSet = Conn.Execute("Select d.partnerID As globalPartnerID From (tblDealerEmployee de INNER JOIN tblDealer d ON d.dealerID = de.dealerID) Where de.dealerEmployeeID = " & flsPartnerWebID & "")
            If Not RecSet.EOF Then
                globalPartnerID = RecSet.Fields("globalPartnerID").Value
            End If
            RecSet.Close()
            RecSet = Nothing
            dbClose()
        End If
        Response.Write("<table height='100' width='100%' cellpadding='0' cellspacing='0' background='gui/menu_main.jpg'>")
        Response.Write("<tr>")
        Response.Write("<td valign='top' align='left'><img src='gui/partner_gui/left_partnerID" & globalPartnerID & ".png'></td>")
        Response.Write("<td valign='top' align='right'><img src='gui/partner_gui/right_partnerID" & globalPartnerID & ".png'></td>")
        Response.Write("<td align='right' width='1'><img src='gui/menu_main.jpg'></td>")
        Response.Write("</tr>")
        Response.Write("</table>")
    End Sub

    Public Sub OverPrint()
        Response.Write("<html>")
        Response.Write("<head>")
        Response.Write("<title>FLS Partner Web - Print</title>")
        Response.Write("<link href='style.css' rel='stylesheet' type='text/css'>")
        Response.Write("  <style media=""print"">" & vbCr)
        Response.Write("  .noprint { display: none }" & vbCr)
        Response.Write("  </style>" & vbCr)
        Response.Write("<script defer>" & vbCr)
        Response.Write("  function window.onload() {" & vbCr)
        Response.Write("    factory.printing.header = """"" & vbCr)
        Response.Write("    factory.printing.footer = """"" & vbCr)
        Response.Write("    factory.printing.portrait = true" & vbCr)
        Response.Write("  }" & vbCr)
        Response.Write("    function printWindow() {" & vbCr)
        Response.Write("    bV = parseInt(navigator.appVersion);" & vbCr)
        Response.Write("    if (bV >= 4) window.print();return true" & vbCr)
        Response.Write("  }" & vbCr)
        Response.Write("  </script>" & vbCr)
        Response.Write("<object id=""factory"" viewastext  style=""display:none""" & vbCr)
        Response.Write("    classid=""clsid:1663ed61-23eb-11d2-b92f-008048fdd814""" & vbCr)
        Response.Write("    codebase=""smsx.cab#Version=6,3,435,20"">" & vbCr)
        Response.Write("  </object>" & vbCr)
        Response.Write("</head>")
        Response.Write("<body>")
    End Sub

    Public Sub Under()
        Response.Write("</div>")
        Response.Write("</body>")
        Response.Write("</html>")
    End Sub

    Public Sub CompanyAddressSQL()
        dbOpen()
        RecSet = Conn.Execute("Select co.company, co.street, co.zipcode, co.city, co.telephone, co.fax, co.email, co.homepage, co.cin, c.country From (tblCompany co INNER Join tblCountry c ON c.countryID = co.companyID) Where co.countryID = " & countryID & "")
        If Not RecSet.EOF Then
            coCompany = RecSet.Fields("company").Value
            coStreet = RecSet.Fields("street").Value
            coZipcode = RecSet.Fields("zipcode").Value
            coCity = RecSet.Fields("city").Value
            coTelephone = RecSet.Fields("telephone").Value
            coFax = RecSet.Fields("fax").Value
            coEmail = RecSet.Fields("email").Value
            coHomepage = RecSet.Fields("homepage").Value
            coCountry = RecSet.Fields("country").Value
            coCin = RecSet.Fields("cin").Value
        End If
        RecSet.Close()
        RecSet = Nothing
        dbClose()
    End Sub

    Public Sub CompanyAddress()
        Response.Write("<table cellpadding='0' cellspacing='0'>")
        Response.Write("<tr><td colspan='2'><img src='gui/fragus_logo.jpg'></td></tr>")
        Response.Write("<tr><td><br></td></tr>")
        Response.Write("<tr><td colspan='2' class='printBold'>" & coCompany & "</td></tr>")
        Response.Write("<tr><td><br></td></tr>")
        Response.Write("<tr><td class='printRegular' valign='top'>Address:</td><td class='printRegular'>" & coStreet & "<br>" & coZipcode & " " & coCity & "<br>" & coCountry & "</td></tr>")
        Response.Write("<tr><td class='printRegular'>Phone:</td><td class='printRegular'>" & coTelephone & "</td></tr>")
        Response.Write("<tr><td class='printRegular'>Fax:</td><td class='printRegular'>" & coFax & "</td></tr>")
        Response.Write("<tr><td class='printRegular'>E-mail:</td><td class='printRegular'>" & coEmail & "</td></tr>")
        Response.Write("<tr><td class='printRegular'>Homepage:</td><td class='printRegular'>" & coHomepage & "</td></tr>")
        Response.Write("<tr><td class='printRegular'>Company ID:</td><td class='printRegular'>" & coCin & "</td></tr>")
        Response.Write("<tr><td><br></td></tr>")
        Response.Write("<tr><td colspan='2' class='printRegular'>" & coCompany & ", a subsidiary to AB Svensk Bilgaranti</td></tr>")
        Response.Write("</table>")
    End Sub

    Public Sub checkFields()
        Response.Write("<script type=""text/javascript"">" & vbCr)
        Response.Write("<!--" & vbCr)
        Response.Write("function _(id) {" & vbCr)
        Response.Write("    return document.getElementById(id);" & vbCr)
        Response.Write("}" & vbCr)
        Response.Write("function scrollToError(elemId)" & vbCr)
        Response.Write("{" & vbCr)
        Response.Write("    if (window.scrollTo) {" & vbCr)
        Response.Write("	var el = _(elemId);" & vbCr)
        Response.Write("	var pos = 0;" & vbCr)
        Response.Write("	// Calculate the position" & vbCr)
        Response.Write("	while (el) {" & vbCr)
        Response.Write("            pos += el.offsetTop;" & vbCr)
        Response.Write("            el = el.offsetParent;" & vbCr)
        Response.Write("	}" & vbCr)
        Response.Write("	if (typeof(document.body.topMargin) == 'number')" & vbCr)
        Response.Write("            pos += document.body.topMargin;" & vbCr)
        Response.Write("        if (pos > 100)" & vbCr)
        Response.Write("            pos -= 100;" & vbCr)
        Response.Write("        " & vbCr)
        Response.Write("	// Scroll" & vbCr)
        Response.Write("        window.scrollTo(0, pos);" & vbCr)
        Response.Write("    }" & vbCr)
        Response.Write("    // Focus " & vbCr)
        Response.Write("    _(elemId).focus();" & vbCr)
        Response.Write("} " & vbCr)
        Response.Write("// sorted in top-to-bottom order" & vbCr)
        Response.Write("var checks = [")
        Response.Write(strJS)
        Response.Write("];" & vbCr)
        Response.Write("var error;" & vbCr)
        Response.Write("var firstfield;" & vbCr)
        Response.Write("function badfield( _field )" & vbCr)
        Response.Write("{" & vbCr)
        Response.Write("    _(""error_""+_field).style.display = 'block';" & vbCr)
        Response.Write("    if (!error) {" & vbCr)
        Response.Write("        firstfield = _field;" & vbCr)
        Response.Write("        error=true;" & vbCr)
        Response.Write("    }" & vbCr)
        Response.Write("}" & vbCr)
        Response.Write("function checkFields()" & vbCr)
        Response.Write("{" & vbCr)
        Response.Write("    error = false;" & vbCr)
        Response.Write("    firstfield = null;" & vbCr)
        Response.Write("    try {" & vbCr)
        Response.Write("        for (i=0; i<checks.length; i++) {" & vbCr)
        Response.Write("            var field = checks[i][0];" & vbCr)
        Response.Write("            var condition = checks[i][1];" & vbCr)
        Response.Write("            var value = _(field).value;" & vbCr)
        Response.Write("            " & vbCr)
        Response.Write("            // check that field is non-empty" & vbCr)
        Response.Write("            if (value && value.length < 1) {" & vbCr)
        Response.Write("                badfield(field);" & vbCr)
        Response.Write("                continue;" & vbCr)
        Response.Write("            }" & vbCr)
        Response.Write("            // check that field is correct" & vbCr)
        Response.Write("            expr = ""'"" + value + ""'"" + condition;" & vbCr)
        Response.Write("            if (eval(expr) == true) {" & vbCr)
        Response.Write("                badfield(field);" & vbCr)
        Response.Write("                continue;" & vbCr)
        Response.Write("            }" & vbCr)
        Response.Write("            _(""error_""+field).style.display = 'none';" & vbCr)
        Response.Write("        }" & vbCr)
        Response.Write("        if (error)" & vbCr)
        Response.Write("            scrollToError(firstfield);" & vbCr)
        Response.Write("    }" & vbCr)
        Response.Write("    catch (e) {" & vbCr)
        Response.Write("        //alert(e.message ? e.message : e.description);" & vbCr)
        Response.Write("    }" & vbCr)
        Response.Write("        " & vbCr)
        Response.Write("    return !error;" & vbCr)
        Response.Write("}" & vbCr)
        Response.Write("-->" & vbCr)
        Response.Write("</script>" & vbCr)
    End Sub

    Public Sub insertFonts()
        Response.Write("<script type=""text/javascript"">" & vbCr)
        Response.Write("<!--")
        Response.Write("var carret=null,fieldobj=null,ie=(document.selection&&document.selection.createRange);")
        Response.Write("function storepos(obj){ ")
        Response.Write("   fieldobj=obj; carret=(ie)?document.selection.createRange():null; ")
        Response.Write("}")
        Response.Write("function saveScrollCoordinates()")
        Response.Write("{")
        Response.Write("	//scrollx = (document.all)?document.body.scrollLeft:window.pageXOffset;")
        Response.Write("	//scrolly = (document.all)?document.body.scrollTop:window.pageYOffset;")
        Response.Write("}")
        Response.Write("function insertAtCarret(str){")
        Response.Write("   if(!fieldobj) return null;")
        Response.Write("   if (carret){")
        Response.Write("      carret.text=str; carret.select();")
        Response.Write("   } else if(document.getElementById&&!ie) {")
        Response.Write("      fieldobj.value=fieldobj.value.substring(0,fieldobj.selectionStart)+str+fieldobj.value.substring(fieldobj.selectionEnd);")
        Response.Write("      fieldobj.focus();")
        Response.Write("   } else {")
        Response.Write("      fieldobj.value+=str;")
        Response.Write("      fieldobj.focus();")
        Response.Write("   }")
        Response.Write("}")
        Response.Write("-->")
        Response.Write("</script>" & vbCr)
    End Sub

    Public Sub selectSub()
        Response.Write("<script language=""JavaScript"">" & vbCr)
        Response.Write("var DomYes=document.getElementById?1:0;" & vbCr)
        Response.Write("function set_child_listbox(parentObject,childObject,childArray,spanToHide) {" & vbCr)
        Response.Write("	//Clear child listbox" & vbCr)
        Response.Write("	for(var i=childObject.length;i>0;i--) {" & vbCr)
        Response.Write("		childObject.options[i] = null;" & vbCr)
        Response.Write("	} " & vbCr)
        Response.Write("	" & vbCr)
        Response.Write("	childObject.options[0] = new Option("" ")
        Response.Write(strSelectSubHeadline)
        Response.Write(" "","""");" & vbCr)
        Response.Write("	var sel_index = parentObject.options[parentObject.selectedIndex].value;" & vbCr)
        Response.Write("	if (sel_index == """") {" & vbCr)
        Response.Write("		childObject.disabled = true;" & vbCr)
        Response.Write("	} else {" & vbCr)
        Response.Write("		childObject.disabled = false;" & vbCr)
        Response.Write("		var childIndex = 1;" & vbCr)
        Response.Write("		for (i = 0; i < childArray.length; i++) {" & vbCr)
        Response.Write("			if (childArray[i][1] == sel_index) {" & vbCr)
        Response.Write("				childObject.options[childIndex] = new Option(childArray[i][2], childArray[i][0]);" & vbCr)
        Response.Write("				childIndex++;" & vbCr)
        Response.Write("			}" & vbCr)
        Response.Write("		}" & vbCr)
        Response.Write("	}" & vbCr)
        Response.Write("	//Select first option" & vbCr)
        Response.Write("	childObject.selectedIndex = 0;" & vbCr)
        Response.Write("}" & vbCr)
        Response.Write("var Product = new Array(")
        Response.Write(strSelectSubJS)
        Response.Write(");" & vbCr)
        Response.Write("</script>" & vbCr)
    End Sub


End Class
